package com.txc.books.controller;

import com.txc.books.entity.FilingRecords;
import com.txc.books.entity.User;
import com.txc.books.exception.BaseException;
import com.txc.books.service.IFilingRecordsService;
import com.txc.books.utils.PageRequest;
import com.txc.books.utils.PageResult;
import org.springframework.web.bind.annotation.*;

/**
 * @author: XCTANG
 *
 */

@RestController
@RequestMapping("/filing")
public class FilingRecordsController {

    private IFilingRecordsService filingRecordsService;

    public FilingRecordsController(IFilingRecordsService filingRecordsService){
        this.filingRecordsService = filingRecordsService;
    }

    //查找全部归档记录
    @GetMapping(value = "/findAll")
    public void findAll(){
        filingRecordsService.findAll();
    }

    //添加归档记录
    @PostMapping(value = "/insert")
    public void addUser(FilingRecords filingRecords){
        try{
            filingRecordsService.insert(filingRecords);
        }catch (BaseException e){
            System.out.println("出现定义的异常");
        }catch (Exception e){
            System.out.println("出现不可预料的异常");
        }
    }

    //更新归档记录
    @PostMapping(value = "/update")
    public void updateUser(FilingRecords filingRecords){

        try{
            filingRecordsService.update(filingRecords);
        }catch (BaseException e){
            System.out.println("出现定义的异常");
        }catch (Exception e){
            System.out.println("出现不可预料的异常");
        }
    }


    //删除归档记录
    @GetMapping(value = "/delete")
    public void deleteUser(@RequestParam("id") String id){
        filingRecordsService.delete(Integer.parseInt(id.trim()));
    }

    //根据id查询归档记录
    @GetMapping(value = "/select")
    public void select(@RequestParam("id") String id){
        filingRecordsService.select(Integer.parseInt(id));
    }

    //分页查询
    @GetMapping(value="/findPage")
    public PageResult findPage(PageRequest pageQuery) {
        return filingRecordsService.findByPager(pageQuery);
    }
}
